/*
题目链接:https://leetcode.cn/problems/count-largest-group/description/?envType=daily-question&envId=2025-04-23
*/

//题解代码:
class Solution {
public:
    unordered_map<int,int> ump;
    int f(int x){
        int ret = 0;
        while(x){
            ret += x%10;
            x/=10;
        }
        return ret;
    }
    int countLargestGroup(int n) {
        for(int i=1;i<=n;++i){
            ump[f(i)]++;
        }
        int mx = 0;
        for(auto& it : ump){
            mx = max(mx,it.second);
        }
        int ans = 0;
        for(auto& it : ump){
            ans += it.second == mx;
        }
        return ans;
    }
};
